/*****************************************************************************
* Author:		Wesley Maxey
* Information:	CST 238 Lab 1 GUI Basics
* Filename:		Lab_1.cpp
* Date Created:	4/10/2013
*
* Overview:
*	String class that creates an extremely simple interface for building
*	strings out of different native types (int, char *, bool, etc... )
*
* Member Functions:
*public:
*	SuperString()
*	SuperString( const Tx ... )
*	void setString( const Tx ... )
*	char * getString()
*	~SuperString()
*private:
*	void unwindArgs( const T, const Tx ... )
*	void unwindArgs()
*	void extractType() //Heavily overloaded function for deducing base type
*
* Contained Data:
*private:
*	char * m_str
*	int m_len
*
*****************************************************************************/

#include <Windows.h>
#include <mmsystem.h>
//This here is my cool contribution to Lab 1
#include "SuperString.h"

LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);

int WINAPI WinMain( HINSTANCE hInst, HINSTANCE hPrevInst,
					PSTR lpszCmdParam, int nCmdShow ) {
	static char		szAppName[] = "Wesley Maxey - Lab 1";
	HWND			hwnd;
	MSG				msg;
	WNDCLASSEX		wndclass; 

	SuperString		temp("test ", 1, 2, 3, 4, 5 );

	wndclass.cbSize 		 = sizeof(wndclass);
	wndclass.style         = CS_HREDRAW | CS_VREDRAW;
	wndclass.lpfnWndProc   = WndProc;
	wndclass.cbClsExtra    = 0;
	wndclass.cbWndExtra    = 0;
	wndclass.hInstance     = hInst;
	wndclass.hIcon         = LoadIcon (NULL, IDI_APPLICATION);

	wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW);
	wndclass.hbrBackground = WHITE_BRUSH;
	wndclass.lpszMenuName  = NULL;
	wndclass.lpszClassName = szAppName;
	wndclass.hIconSm       = LoadIcon (NULL, IDI_APPLICATION);

	RegisterClassEx (&wndclass);


	hwnd = CreateWindow (szAppName,		// window class name
		"CST 238 - Example 1",			// window caption
		WS_OVERLAPPEDWINDOW,			// window style
		CW_USEDEFAULT,					// initial x position
		CW_USEDEFAULT,					// initial y position
		CW_USEDEFAULT,					// initial x size
		CW_USEDEFAULT,					// initial y size
		NULL,							// parent window handle
		NULL,							// window menu handle
		hInst,							// program instance handle
		NULL);							// creation parameters

	ShowWindow (hwnd, nCmdShow);
	UpdateWindow (hwnd);

	while (GetMessage (&msg, NULL, 0, 0))
	{
		TranslateMessage (&msg);
		DispatchMessage (&msg);
	}
	return (int)(msg.wParam);
}

LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
	HDC			hdc;
	PAINTSTRUCT	ps;
	RECT		rect;
	HRGN		hrgn;
	SuperString superstring;	//Custom string class added as my special feature
	char		buffer[8];
	char		output[64];
	int			x, y;
	static	int	rmb_clicks = 0;
	static	int	lmb_clicks = 0;

	switch (message)
	{
	case WM_LBUTTONUP:
		lmb_clicks++;
		GetClientRect( hwnd, &rect );
		SendMessage( hwnd, WM_PAINT, wParam, lParam );
		InvalidateRect( hwnd, &rect, FALSE );
		return 0;

	case WM_RBUTTONUP:
		rmb_clicks++;
		GetClientRect( hwnd, &rect );
		superstring.setString( "WINDOW SIZE: ",	rect.right,	" X ", rect.bottom );
		MessageBox( hwnd, superstring.getString(), "RMB Pressed", MB_OK );
		SendMessage( hwnd, WM_PAINT, wParam, lParam );
		InvalidateRect( hwnd, &rect, FALSE );

		return 0;

	case WM_PAINT:
		hdc = BeginPaint (hwnd, &ps);

		GetClientRect (hwnd, &rect);
		x = rect.bottom;
		y = rect.right;

		FillRect( hdc, &rect, RGB(256, 256, 256) );
		superstring.setString( "WINDOW SIZE: ", rect.right, " X ", rect.bottom );
		DrawText( hdc, superstring.getString(), -1, &rect, DT_TOP );

		rect.top += 20;
		superstring.setString( "TOP: ",	rect.top, " LEFT: ", rect.left,
			" RIGHT: ", rect.right, " BOTTOM: ", rect.bottom );
		DrawText( hdc, superstring.getString(), -1, &rect,  DT_TOP );

		rect.top += 20;
		superstring.setString( "RMB CLICKS: ", rmb_clicks );
		DrawText( hdc, superstring.getString(), -1, &rect,  DT_TOP );

		rect.top += 20;
		superstring.setString( "LMB CLICKS: ", lmb_clicks );
		DrawText( hdc, superstring.getString(), -1, &rect,  DT_TOP );

		EndPaint ( hwnd, &ps );

		return 0;

	case WM_CREATE:
		PlaySound( "sfile.wav", NULL, SND_SYNC | SND_FILENAME );

		return 0;

	case WM_DESTROY:
		PostQuitMessage (0);

		return 0;
	}

	return DefWindowProc (hwnd, message, wParam, lParam);
}